/**
 * @author zhouyanxiang
 * @create 2020-11-2020/11/14-22:02
 */
public class ShellSort {

    public static void main(String[] args) {
        int[] arr =  {0,-8,5,1,33,6,9,2,-1};
        shellSort(arr);
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }

    public static void shellSort(int[] arr) {
        int length = arr.length;
        int tmp;
        for (int step = length / 2; step >= 1 ; step/=2) {
            for (int i = step; i < length; i++) {
                tmp = arr[i];
                int j = i - step;
                while (j >= 0 && arr[j] > tmp) {
                    arr[j+step] = arr[j];
                    j-=step;
                }
                arr[j+step] = tmp;
            }
        }
    }
}
